﻿using System;

namespace Game
{
    public class BuffManager
    {
        public ComponentPlayer componentPlayer;

        public BuffManager(ComponentPlayer player)
        {
            componentPlayer = player;
        }

        public void StopBuffs()
        {
            ComponentHealBuffA componentHealBuffA = componentPlayer.Entity.FindComponent<ComponentHealBuffA>();
            ComponentAttackUP componentAttackUP = componentPlayer.Entity.FindComponent<ComponentAttackUP>();
            ComponentSpeedUP componentSpeedUP = componentPlayer.Entity.FindComponent<ComponentSpeedUP>();
            ComponentNightsight componentNightsight = componentPlayer.Entity.FindComponent<ComponentNightsight>();
            ComponentBlind componentBlind = componentPlayer.Entity.FindComponent<ComponentBlind>();
            ComponentSlowDown componentSlowDown = componentPlayer.Entity.FindComponent<ComponentSlowDown>();
            ComponentJump componentJump = componentPlayer.Entity.FindComponent<ComponentJump>();
            ComponentDizzy componentDizzy = componentPlayer.Entity.FindComponent<ComponentDizzy>();
            componentHealBuffA.StopBuff();
            componentAttackUP.StopBuff();
            componentSpeedUP.StopBuff();
            componentNightsight.StopBuff();
            componentBlind.StopBuff();
            componentSlowDown.StopBuff();
            componentJump.StopBuff();
            componentDizzy.StopBuff();
        }

        public void AddBuffOnUse(int buffType, int activeBlockValue, float duration, float rate)
        {
            switch (activeBlockValue)
            {
                case 932:
                    {
                        ComponentHealBuffA componentHealBuffA = componentPlayer.Entity.FindComponent<ComponentHealBuffA>();
                        componentHealBuffA.StartHealBuff(duration, rate);
                        break;
                    }
                case 968:
                    break;
                default:
                    throw new ArgumentException("Unknown active block value");
            }
        }

        public void AddBuff(int buffType, float duration, float rate = 1f)
        {
            switch (buffType)
            {
                case 1:
                    {
                        float num12 = 120f;
                        float num13 = 10f;
                        ComponentHealBuffA componentHealBuffA = componentPlayer.Entity.FindComponent<ComponentHealBuffA>();
                        if (componentHealBuffA == null)
                        {
                            break;
                        }

                        if (!componentHealBuffA.IsActive)
                        {
                            componentHealBuffA.StartHealBuff(duration, rate);
                            break;
                        }

                        if (componentHealBuffA.m_HealDuration > num12)
                        {
                            componentHealBuffA.m_HealDuration = num12;
                        }
                        else if (componentHealBuffA.m_HealDuration < num12)
                        {
                            componentHealBuffA.m_HealDuration += 10f;
                            if (componentHealBuffA.m_HealDuration > num12)
                            {
                                componentHealBuffA.m_HealDuration = num12;
                            }
                        }

                        if (componentHealBuffA.m_HealRate > num13)
                        {
                            componentHealBuffA.m_HealRate = num13;
                        }
                        else if (componentHealBuffA.HealingRate < num13)
                        {
                            componentHealBuffA.m_HealRate = 1.01f * componentHealBuffA.m_HealRate;
                            if (componentHealBuffA.m_HealRate > num13)
                            {
                                componentHealBuffA.m_HealRate = num13;
                            }
                        }

                        break;
                    }
                case 2:
                    {
                        ComponentAttackUP componentAttackUP = componentPlayer.Entity.FindComponent<ComponentAttackUP>();
                        float num7 = 120f;
                        float num8 = 20f;
                        float num9 = 1.5f;
                        if (componentAttackUP == null)
                        {
                            break;
                        }

                        if (!componentAttackUP.IsActive)
                        {
                            componentAttackUP.StartATKBuff(duration, rate);
                            break;
                        }

                        float aTK_first = componentAttackUP.ATK_first;
                        if (componentAttackUP.m_ATKDuration > num7)
                        {
                            componentAttackUP.m_ATKDuration = num7;
                        }
                        else if (componentAttackUP.m_ATKDuration < num7)
                        {
                            componentAttackUP.m_ATKDuration += 10f;
                            if (componentAttackUP.m_ATKDuration > num7)
                            {
                                componentAttackUP.m_ATKDuration = num7;
                            }
                        }

                        if (componentPlayer.ComponentMiner.AttackPower > num8 + aTK_first)
                        {
                            componentPlayer.ComponentMiner.AttackPower = num8 + aTK_first;
                        }
                        else if (componentPlayer.ComponentMiner.AttackPower < num8 + aTK_first)
                        {
                            componentPlayer.ComponentMiner.AttackPower = componentPlayer.ComponentMiner.AttackPower * num9;
                            if (componentPlayer.ComponentMiner.AttackPower > num8 + aTK_first)
                            {
                                componentPlayer.ComponentMiner.AttackPower = num8 + aTK_first;
                            }
                        }

                        break;
                    }
                case 3:
                    {
                        ComponentSpeedUP componentSpeedUP = componentPlayer.Entity.FindComponent<ComponentSpeedUP>();
                        float num3 = 120f;
                        float num4 = 12f;
                        float num5 = 1.5f;
                        if (componentSpeedUP == null)
                        {
                            break;
                        }

                        if (!componentSpeedUP.IsActive)
                        {
                            componentSpeedUP.StartSpeedBuff(duration, rate);
                            break;
                        }

                        float speed_first = componentSpeedUP.Speed_first;
                        if (componentSpeedUP.m_SpeedDuration > num3)
                        {
                            componentSpeedUP.m_SpeedDuration = num3;
                        }
                        else if (componentSpeedUP.m_SpeedDuration < num3)
                        {
                            componentSpeedUP.m_SpeedDuration += 10f;
                            if (componentSpeedUP.m_SpeedDuration > num3)
                            {
                                componentSpeedUP.m_SpeedDuration = num3;
                            }
                        }

                        if (componentPlayer.ComponentLocomotion.WalkSpeed > num4 + speed_first)
                        {
                            componentPlayer.ComponentLocomotion.WalkSpeed = num4 + speed_first;
                        }
                        else if (componentPlayer.ComponentLocomotion.WalkSpeed < num4 + speed_first)
                        {
                            componentPlayer.ComponentLocomotion.WalkSpeed = componentPlayer.ComponentLocomotion.WalkSpeed * num5;
                            if (componentPlayer.ComponentLocomotion.WalkSpeed > num4 + speed_first)
                            {
                                componentPlayer.ComponentLocomotion.WalkSpeed = num4 + speed_first;
                            }
                        }

                        break;
                    }
                case 9:
                    {
                        ComponentNightsight componentNightsight = componentPlayer.Entity.FindComponent<ComponentNightsight>();
                        float num10 = 240f;
                        if (componentNightsight == null)
                        {
                            break;
                        }

                        if (!componentNightsight.IsActive)
                        {
                            componentNightsight.StartNightsightBuff(duration);
                        }
                        else if (componentNightsight.m_NightseeDuration > num10)
                        {
                            componentNightsight.m_NightseeDuration = num10;
                        }
                        else if (componentNightsight.m_NightseeDuration < num10)
                        {
                            componentNightsight.m_NightseeDuration += 60f;
                            if (componentNightsight.m_NightseeDuration > num10)
                            {
                                componentNightsight.m_NightseeDuration = num10;
                            }
                        }

                        break;
                    }
                case 4:
                    {
                        ComponentBlind componentBlind = componentPlayer.Entity.FindComponent<ComponentBlind>();
                        float num11 = 5f;
                        if (componentBlind == null)
                        {
                            break;
                        }

                        if (!componentBlind.IsActive)
                        {
                            componentBlind.StartBlindBuff(duration, rate);
                        }
                        else if (componentBlind.m_BlindDuration > num11)
                        {
                            componentBlind.m_BlindDuration = num11;
                        }
                        else if (componentBlind.m_BlindDuration < num11)
                        {
                            componentBlind.m_BlindDuration += 5f;
                            if (componentBlind.m_BlindDuration > num11)
                            {
                                componentBlind.m_BlindDuration = num11;
                            }
                        }

                        break;
                    }
                case 6:
                    {
                        ComponentSlowDown componentSlowDown = componentPlayer.Entity.FindComponent<ComponentSlowDown>();
                        float num6 = 5f;
                        if (componentSlowDown == null)
                        {
                            break;
                        }

                        if (!componentSlowDown.IsActive)
                        {
                            componentSlowDown.StartBuff(duration, rate);
                        }
                        else if (componentSlowDown.m_SlowDuration > num6)
                        {
                            componentSlowDown.m_SlowDuration = num6;
                        }
                        else if (componentSlowDown.m_SlowDuration < num6)
                        {
                            componentSlowDown.m_SlowDuration += 5f;
                            if (componentSlowDown.m_SlowDuration > num6)
                            {
                                componentSlowDown.m_SlowDuration = num6;
                            }
                        }

                        break;
                    }
                case 10:
                    {
                        ComponentJump componentJump = componentPlayer.Entity.FindComponent<ComponentJump>();
                        float num2 = 120f;
                        if (componentJump == null)
                        {
                            break;
                        }

                        if (!componentJump.IsActive)
                        {
                            componentJump.StartJumpBuff(duration, rate);
                        }
                        else if (componentJump.m_JumpDuration > num2)
                        {
                            componentJump.m_JumpDuration = num2;
                        }
                        else if (componentJump.m_JumpDuration < num2)
                        {
                            componentJump.m_JumpDuration += 20f;
                            if (componentJump.m_JumpDuration > num2)
                            {
                                componentJump.m_JumpDuration = num2;
                            }
                        }

                        break;
                    }
                case 11:
                    {
                        ComponentDizzy componentDizzy = componentPlayer.Entity.FindComponent<ComponentDizzy>();
                        float num = 5f;
                        if (componentDizzy == null)
                        {
                            break;
                        }

                        if (!componentDizzy.IsActive)
                        {
                            componentDizzy.StartDizzyBuff(duration, rate);
                        }
                        else if (componentDizzy.m_DizzyDuration > num)
                        {
                            componentDizzy.m_DizzyDuration = num;
                        }
                        else if (componentDizzy.m_DizzyDuration < num)
                        {
                            componentDizzy.m_DizzyDuration += 3f;
                            if (componentDizzy.m_DizzyDuration > num)
                            {
                                componentDizzy.m_DizzyDuration = num;
                            }
                        }

                        break;
                    }
                default:
                    throw new ArgumentException("Unknown buff type");
            }
        }
    }
}